package com.lianyu507.tools;

import com.lianyu507.tools.youdao.Result;
import com.lianyu507.util.HttpClientUtil;
import com.lianyu507.util.JsonUtils;

import java.util.List;

public class TranslateTool {
    private static final String TRANSLATE_URL = "http://fanyi.youdao.com/openapi.do?keyfrom=pizahouse&key=1517817920&type=data&doctype=json&version=1.1&q=";

    public static String convertYoudaoSigleWord(String english) {
        String json = HttpClientUtil.doGet(TRANSLATE_URL + english);

        Result result = JsonUtils.jsonToPojo(json, Result.class);
        String Chinase = "";

        if (result != null) {
            List<String> translation = result.getTranslation();
            if (translation.size() > 0) {
                Chinase = translation.get(0);
            }
        }
        return Chinase;
    }

//    public static void main(String[ ] args){
//        String english = convertYoudaoSigleWord("Yours");
//        System.out.println(english);
//    }

}
